﻿<metro:Window x:Class="D3StatsClient.View.SessionPickerWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:metro="http://schemas.codeplex.com/elysium"
        xmlns:params="http://schemas.codeplex.com/elysium/params"
        xmlns:converters="clr-namespace:D3StatsClient.Converters"
        Title="Session Picker" Height="340" MinHeight="340" MinWidth="700" Width="700">
    <Window.Resources>
        <converters:BoolToVisibilityConverter x:Key="InvertedBoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible" />
        <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Hidden" />
    </Window.Resources>
    <StackPanel>
        <TextBlock Margin="10,0,0,0" Text="{Binding Sessions.Count, StringFormat=Total Sessions({0}) }" />
        
        <DataGrid DockPanel.Dock="Top"
            Background="{Binding BackgroundColor}"
            Foreground="{Binding ForegroundColor}"
            AutoGenerateColumns="False"
            SelectedItem="{Binding SelectedSession}" 
            ItemsSource="{Binding Sessions}"
            CanUserAddRows="False"
            CanUserResizeColumns="True"
            CanUserDeleteRows="False"
            CanUserSortColumns="True"
            SelectionMode="Single"
            GridLinesVisibility="None"
            HeadersVisibility="Column"
            ScrollViewer.HorizontalScrollBarVisibility="Hidden"
            ScrollViewer.CanContentScroll="True"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
            Height="240">
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="BorderThickness" Value="0" />
                    <Setter Property="BorderBrush" Value="Transparent" />
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="" CanUserSort="False" Width="114" CanUserResize="False" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Button Content="Delete" CommandParameter="{Binding}" Command="{Binding Path=DataContext.DeleteSessionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" />
                                        <Button Margin="3,0,0,0" Visibility="{Binding IsUploading, Converter={StaticResource InvertedBoolToVisibilityConverter}}" Content="Upload" CommandParameter="{Binding}" Command="{Binding Path=DataContext.UploadSessionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" />
                                        <metro:ProgressRing Margin="20,0,0,0" State="Indeterminate" ToolTip="Currently Uploading Session to server..." IsEnabled="true" Visibility="{Binding IsUploading, Converter={StaticResource BoolToVisibilityConverter}}" Height="16" Width="16" />
                                    </StackPanel>
                                </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Name" Width="180" CanUserSort="True" SortMemberPath="Name" CanUserResize="False" IsReadOnly="True"> 
                        <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding Name}" />
                                    </StackPanel>
                                </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                <DataGridTextColumn Header="Start Time" Binding="{Binding StartTime}" Width="140" CanUserResize="False" IsReadOnly="True"/>
                <DataGridTextColumn Header="End Time" Binding="{Binding EndTime}" Width="140" CanUserResize="False" IsReadOnly="True"/>
                <DataGridTextColumn Header="Played" Binding="{Binding Played}" Width="70" CanUserResize="False" IsReadOnly="True"/>
                <DataGridTextColumn Header="Drops" Binding="{Binding TotalDrops}" Width="50" CanUserResize="False" IsReadOnly="True"/>
            </DataGrid.Columns>
        </DataGrid>
        
        <StackPanel>
            <DockPanel HorizontalAlignment="Right">
                <Button HorizontalAlignment="Left" Command="{Binding OpenSessionsFolderCommand}" Content="View Source Folder" Width="130" Margin="0,10,380,10"/>
                <Button Content="Cancel" Width="75" Margin="0,10,10,10" Click="Button_Click_1" />
                <Button IsDefault="True" Content="Load" Width="75" Margin="0,10,10,10" Click="Button_Click_2" Command="{Binding LoadSessionCommand}"/>
            </DockPanel>
        </StackPanel>
        
    </StackPanel>
</metro:Window>
